<template>
  <div class="OKRDataList">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="周期" class="myform-item">
          <el-select v-model="form.time" placeholder="请选择">
            <el-option
              v-for="item in datalist"
              :key="item"
              :label="item"
              :value="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="员工姓名" class="myform-item">
          <el-input
            v-model="form.user_name"
            placeholder="请输入员工姓名"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>

        <el-form-item label="部门" class="myform-item">
          <el-cascader
            v-model="open_department_id"
            :options="department"
            @change="changeD"
            clearable
            :props="Props"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="评级状态" class="myform-item">
          <el-select
            v-model="form.status"
            placeholder="请选择"
            clearable
            @keyup.enter.native="onSearch"
          >
            <el-option
              v-for="item in pjlist"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px" class="myform-item">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" @row-click="RowClick">
      <el-table-column label="员工" align="center" prop="user_info">
        <template slot-scope="{ row }">
          <div class="userinfo">
            <el-image
              :src="row.user_info.feishu_avatar.avatar_origin"
              :lazy="true"
              :preview-src-list="[row.user_info.feishu_avatar.avatar_origin]"
            ></el-image>
            {{ row.user_info.username }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="直属上级" align="center" prop="user_top_info">
        <template slot-scope="{ row }">
          <div class="userinfo">
            <el-image :src="row.user_top_info.avatar.avatar_origin" :lazy="true" :preview-src-list="[row.user_top_info.avatar.avatar_origin]"></el-image>
            {{ row.user_top_info.name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="Objective"
        align="center"
        prop="content"
      ></el-table-column>
      <el-table-column label="Key Result内容" prop="objective_result_list">
        <template slot-scope="{ row }">
          <div
            v-for="(item, index) in row.objective_result_list"
            :key="item.id"
            style="margin-bottom: 10px"
          >
            KR{{ index + 1 }}：{{ item.content }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="Objective状态" align="center" prop="o_name">
        <template slot-scope="{ row }">
          <div
            class="status"
            :style="{
              background: row.o_color,
            }"
          >
            {{ row.o_name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="Objective评级" align="center" prop="addtime">
        <template slot-scope="{ row }">
          <div
            class="status"
            :style="{
              background: row.o_rating_color,
            }"
          >
            {{ row.o_rating }}
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="
        postHomeWarehouseReservationGetListByCondition
      "
    />
    <el-drawer
      title="OKR"
      :visible.sync="drawer"
      direction="rtl"
      :before-close="handleClose"
      :withHeader="false"
    >
      <div class="drawerclass">
        <div class="drawerclass-module">
          <div>
            <el-image :src="user_info.avatarurl" fit="fill"></el-image>
          </div>
          <div>
            <div>{{ user_info.username }}</div>
            <div>{{ user_info.bm_name }}</div>
          </div>
          <i class="el-icon-close pointer" @click="handleClose"></i>
        </div>
        <el-container>
          <el-main class="drawerclass-main"
            ><div
              class="drawerclass-OKR"
              v-for="(item, index) in data"
              :key="index"
            >
              <div class="drawerclass-OKR-status">
                <div>状态</div>
                <div>评级</div>
              </div>
              <div class="drawerclass-OKR-O">
                <div class="drawerclass-OKR-O-one">O{{ index + 1 }}</div>
                <div class="drawerclass-OKR-O-two">{{ item.content }}</div>
                <div
                  class="drawerclass-OKR-O-three"
                  :style="{
                    background: item.o_color,
                  }"
                >
                  {{ item.name || "暂无" }}
                </div>
                <div
                  class="drawerclass-OKR-O-four"
                  :style="{
                    background: item.pj_color,
                  }"
                >
                  {{ item.pj || "暂无" }}
                </div>
              </div>
              <div
                class="drawerclass-OKR-KR"
                v-for="(e, idx) in item.son"
                :key="idx"
              >
                <div class="drawerclass-OKR-KR-one">KR{{ idx + 1 }}</div>
                <div class="drawerclass-OKR-KR-two">
                  {{ e.content }}
                </div>
                <div
                  class="drawerclass-OKR-KR-three"
                  :style="{
                    background: e.status_color,
                  }"
                >
                  {{ e.status_name || "暂无" }}
                </div>
              </div>
            </div>
          </el-main>
        </el-container>
      </div>
    </el-drawer>
  </div>
</template>


<script>
import {
  postHomeWarehouseReservationGetListByCondition,
  postHomeWarehouseReservationTimeList,
  postHomeObjectiveD_list,
  postHomeObjectiveShow,
} from "@/api";
import pagination from "@/components/paginationLiu.vue";
export default {
  components: { pagination },
  data() {
    return {
      drawer: false,
      Props: {
        value: "open_department_id",
        label: "name",
        children: "son",
        checkStrictly: true,
      },
      open_department_id: [""],
      user_info: "",
      form: {
        dc: 1,
        time: "",
        user_name: "",
        status: "",
        f_department_id: "",
        pageSize: 10,
        page: 1,
      },
      total: 1,
      tableData: [],
      datalist: [],
      department: [],
      pjlist: [
        {
          value: "",
          label: "所有状态",
        },
        {
          value: "1",
          label: "已评级",
        },
        {
          value: "2",
          label: "未评级",
        },
      ],
      data: [], // okr详情
    };
  },
  async mounted() {
    await this.postHomeWarehouseReservationTimeList();
    await this.postHomeObjectiveD_list();
    let { form } = this;
    await this.postHomeWarehouseReservationGetListByCondition(form);
  },
  methods: {
    handleClose() {
      this.data = [];
      this.user_info = "";
      this.drawer = false;
    },
    async RowClick(row, column, event) {
      console.log("row", row);
      this.user_info = row.user_info;
      let { time } = this.form;
      let obj = {
        time,
        user_id: row.user_id,
      };
      let res = await postHomeObjectiveShow(obj);
      console.log("res", res);
      this.data = res.data;
      this.drawer = true;
    },
    async postHomeWarehouseReservationGetListByCondition(data) {
      this.form = data;
      let res = await postHomeWarehouseReservationGetListByCondition(data);
      this.tableData = res.data;
      this.total = Number(res.count);
    },
    async postHomeWarehouseReservationTimeList() {
      let res = await postHomeWarehouseReservationTimeList();
      console.log("res", res);
      let data = res.data;
      this.datalist = data.time;
      this.form.time = data.now;
    },
    async postHomeObjectiveD_list() {
      let obj = {
        type: 2,
      };
      let res = await postHomeObjectiveD_list(obj);
      console.log("res", res);
      let data = res.data;
      this.department = data;
    },
    async changeD(arr) {
      console.log(arr);
      let e = arr[arr.length - 1];
      console.log(e);
      this.form.f_department_id = e;
      let { form } = this;
      this.postHomeWarehouseReservationGetListByCondition(form);
    },
    onSearch() {
      let { form } = this;
      this.postHomeWarehouseReservationGetListByCondition(form);
    },
  },
};
</script>

<style lang="scss" scoped>
.status{
    width:60px;
    color:#ffffff;
    margin:0 auto
}
.drawerclass {
  .drawerclass-main {
    margin-top: 100px;
    height: calc(100vh - 120px);
  }
  .drawerclass-OKR {
    > div:nth-last-child(1) {
      border-bottom: none;
    }
    margin: 0 10px;
    border: 1px solid #cfd3d6;
    padding: 20px;
    border-radius: 4px;
    margin-top: 20px;
    width: 620px;
    .drawerclass-OKR-status {
      display: flex;
      padding-left: 480px;
      padding-bottom: 10px;
      > div {
        width: 60px;
        text-align: center;
        color: #8f959e;
        font-size: 14px;
      }
      > div:nth-child(2) {
        margin-left: 10px;
      }
    }
    .drawerclass-OKR-O {
      display: flex;
      align-items: center;
      border-bottom: 1px solid #cfd3d6;
      padding-bottom: 20px;
      .drawerclass-OKR-O-one {
        background: #2b71d6;
        color: #ffffff;
        width: 60px;
        height: 30px;
        border-radius: 30px;
        text-align: center;
        line-height: 30px;
      }
      .drawerclass-OKR-O-two {
        width: 400px;
        margin: 0 10px;
      }
      .drawerclass-OKR-O-three {
        width: 60px;
        height: 24px;
        line-height: 24px;
        font-size: 14px;
        text-align: center;
        background: #cfd3d6;
        border-radius: 2px;
        color: #fff;
      }
      .drawerclass-OKR-O-four {
        width: 60px;
        height: 24px;
        line-height: 24px;
        font-size: 14px;
        text-align: center;
        background: #cfd3d6;
        border-radius: 2px;
        color: #fff;
        margin-left: 10px;
      }
    }
    .drawerclass-OKR-KR {
      margin-left: 70px;
      display: flex;
      margin-top: 20px;
      border-bottom: 1px solid #cfd3d6;
      padding-bottom: 20px;
      .drawerclass-OKR-KR-one {
        background: #2b71d6;
        color: #ffffff;
        width: 40px;
        height: 24px;
        border-radius: 24px;
        text-align: center;
        line-height: 24px;
        font-size: 12px;
      }
      .drawerclass-OKR-KR-two {
        width: 350px;
        margin: 0 10px;
      }
      .drawerclass-OKR-KR-three {
        width: 60px;
        height: 24px;
        line-height: 24px;
        font-size: 14px;
        text-align: center;
        background: #cfd3d6;
        border-radius: 2px;
        color: #fff;
      }
    }
  }
  .drawerclass-module {
    background: #fff;
    position: fixed;
    top: 0;
    width: 660px;
    display: flex;
    align-items: center;
    margin: 20px 20px;
    border-bottom: 1px solid #cfd3d6;
    padding-bottom: 20px;
    > i {
      position: absolute;
      top: 10px;
      right: 10px;
    }
    > div:nth-child(1) {
      margin-right: 10px;
      > .el-image {
        width: 60px;
        height: 60px;
        border-radius: 50%;
      }
    }
    > div:nth-child(2) {
      > div:nth-child(1) {
        font-size: 20px;
        font-weight: 800;
      }
      > div:nth-child(2) {
        font-size: 14px;
        color: #8f959e;
      }
    }
  }
}
.userinfo {
  display: flex;
  align-items: center;
  justify-content: center;
  > .el-image {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
  }
}
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.OKRDataList {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  /deep/.el-drawer {
    width: 740px !important;
  }
}
</style>